﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ItemComponent;

namespace Battle
{
    public class Bullet_Electricity : BulletBase
    {
        protected new Move_Tween moveComponent;

        public override void InitBulletData(ST_BulletData bulletData, IBulletHitHandler hitHandler, IEnemyTargetGetter targetGetter)
        {
            base.InitBulletData(bulletData, hitHandler,targetGetter);

            SetTarget(targetGetter.GetTarget(transform.position, null));
        }

        protected override void InitMoveComonent()
        {
            if (moveComponent == null)
                moveComponent = gameObject.AddComponent<Move_Tween>();
        }

        /// <summary>
        /// 设置目标
        /// </summary>
        /// <param name="canHitObj"></param>
        protected override void SetTarget(ICanHitObj canHitObj)
        {
            if (canHitObj == null)

                DestorySelf();
            else
                moveComponent.MoveTo(canHitObj.Pos, 0.1f, () =>
                  {
                      OnHitObj(canHitObj);
                  });
        }

        public override void DestorySelf()
        {
            moveComponent.Stop();
            base.DestorySelf();
        }
    }
}
